//
//  ST_DailyFeedController.swift
//  btvideo
//
//  Created by mac on 2021/3/18.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit

class ST_DailyFeedController: UIViewController{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
         
        
        view.addSubview(segment_control)
        segment_control.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalToSuperview().offset((ScreenWidth-95-38*2)/2)
            make.width.equalTo(200)
            make.height.equalTo(ST_MeetYouSegmentControl.height)
        }
        segment_control.selected_closure = {[weak self] idx in
            
            self?.scrollView.setContentOffset(CGPoint.init(x: ScreenWidth*idx.cgFloat, y: 0), animated: true)
        }
        
        
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(segment_control.snp.bottom)
        }
        
        scrollView.addSubview(contentView)
        contentView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
            make.width.equalTo(ScreenWidth*3)
            make.height.equalToSuperview()
        }
        
        self.addChild(recommend_controller)
        contentView.addSubview(recommend_controller.view)
        recommend_controller.view.snp.makeConstraints { (make) in
            make.width.equalTo(ScreenWidth)
            make.left.top.bottom.equalToSuperview()
        }
        
        self.addChild(last_update_controller)
        contentView.addSubview(last_update_controller.view)
        last_update_controller.view.snp.makeConstraints { (make) in
            make.width.height.top.equalTo(recommend_controller.view)
            make.left.equalTo(recommend_controller.view.snp.right)
        }
        
        
        self.addChild(my_follow_controller)
        contentView.addSubview(my_follow_controller.view)
        my_follow_controller.view.snp.makeConstraints { (make) in
            make.width.equalTo(ScreenWidth)
            make.right.top.bottom.equalToSuperview()
        }
        
        NotificationCenter.default.addObserver(self, selector: #selector(member_status_observer), name: Notification.Name.in_pur_status_success, object: nil)
    }
    
    @objc fileprivate func member_status_observer(){
        
    }
    
    
//    MARK: - Properties
    fileprivate lazy var scrollView:UIScrollView = {
       let control = UIScrollView()
//        control.delegate = self
        control.isPagingEnabled = true
        control.isScrollEnabled = false
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        
        return control
    }()
    
    fileprivate lazy var contentView:UIView = {
       let control = UIView()
        return control
    }()
    
    
    fileprivate lazy var recommend_controller = ST_DailyMomentController()
    
    fileprivate lazy var my_follow_controller = ST_FollowedDailyViewController.shared

    fileprivate lazy var last_update_controller = ST_SameCityDailyViewController.shared
    
    
//    fileprivate lazy var segment_control:ST_MeetYouSegmentControl = {
//       let control = ST_MeetYouSegmentControl()
//        control.titleArray = ["推荐","同城","喜欢"]
//        return control
//    }()
    
    fileprivate lazy var segment_control:ST_GitSegmentControl = {
       let control = ST_GitSegmentControl()
        control.space = 38
        control.leftEdge = 0
        control.titleArray = ["推荐","同城","喜欢"]
        return control
    }()
    
    func filter_refresh(){
        
        recommend_controller.refresh_data()
        
        my_follow_controller.refresh_data()
        
        last_update_controller.refresh_data()
    }
}

/*
extension ST_DailyFeedController:UIScrollViewDelegate{
    
    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
                
        
        if !decelerate{
                scrollviewdidEndScroll(scrollView)
        }
    }
    
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
            scrollviewdidEndScroll(scrollView)
        
    }
    
    
//    MARK: 停止滚动
    func scrollviewdidEndScroll(_ scrollView:UIScrollView){
        
        let currPage = (scrollView.contentOffset.x/ScreenWidth).int
        
        
        if currPage == 1 && FETCH_MEMBER_STATUS() != .subscribe && ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex == .male {
            
            //TIANPayManager.shared.source = .附近同城

            ST_BTLaunchController.shared.addChild(self.maskVIPController)
            
            ST_BTLaunchController.shared.view.addSubview(self.maskVIPController.view)
            
            self.segment_control.selectBtn(index: 0)
            
            return
        }
        
        self.segment_control.selectBtn(index: currPage)
        
    }
    
}
*/
